# -*- coding: utf-8 -*-
"""
Created on Sat Jun  6 13:10:37 2020

@author: Matrix
"""

from pydub import AudioSegment
import moviepy
import subprocess
from moviepy.editor import *


bgm_dict = {'Congratulation':1, 
            'Eight':2,
            'Fist':3,
            'Five':4,
            'Four':5,
            'Heart_1':6, 
            'Heart_2':7,
            'Heart_3':8, 
            'Heart_single':9, 
            'Honour':10,
            'ILY':11,
            'Insult':12,
            'Nine':13,
            'OK':14,
            'One':15,
            'Palm_up':16,
            'Prayer':17,
            'Rock':18,
            'Seven':19,
            'Six':20, 
            'Three':21, 
            'Thumb_down':22, 
            'Thumb_up':23, 
            'Two':24  }


#label = ['Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Insult', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Heart_single', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Eight', 'Eight', 'Eight', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Eight', 'Heart_single', 'Eight', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Eight', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Thumb_up', 'Nine', 'Thumb_up', 'Eight', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Eight', 'Eight', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up']
label = ['One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'Nine', 'Eight', 'Eight', 'Two', 'Two', 'Two', 'Two', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'Two', 'ILY', 'ILY', 'ILY', 'ILY', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'Two', 'ILY', 'Two', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Four', 'Five', 'Four', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'Five', 'ILY', 'Five', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Seven', 'Honour', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Eight', 'Heart_single', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Seven', 'Insult', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Fist', 'Thumb_up', 'Palm_up', 'Seven', 'Seven', 'Thumb_down', 'Seven', 'Seven', 'Seven', 'One', 'One', 'One', 'Insult', 'Insult', 'Insult', 'Seven', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Thumb_down', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Seven', 'Seven', 'Seven', 'Thumb_down', 'Prayer', 'Two', 'Two', 'One', 'ILY', 'ILY', 'ILY', 'ILY', 'Two', 'Two', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Palm_up', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Palm_up', 'ILY', 'ILY', 'ILY', 'Rock', 'Rock', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'Two', 'Prayer', 'Nine', 'Nine', 'ILY', 'ILY', 'Eight', 'Eight', 'Insult', 'Insult', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Thumb_up', 'Thumb_up', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Eight', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Thumb_up', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Eight', 'Eight', 'Heart_single', 'Thumb_up', 'Eight', 'One', 'Two', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'Rock', 'ILY', 'Rock', 'Rock', 'Rock', 'Rock', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'ILY', 'Thumb_up', 'Heart_single', 'Insult', 'Seven', 'Seven', 'Eight', 'Eight', 'Heart_single', 'Heart_single', 'Nine', 'Nine', 'Nine', 'Thumb_up', 'Heart_single', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Thumb_up', 'Heart_single', 'Heart_single', 'Thumb_up', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'Heart_single', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'Six', 'Fist', 'Fist', 'Fist', 'Fist', 'Thumb_down', 'Fist', 'Fist', 'Fist', 'Fist', 'Fist', 'Fist', 'Six', 'Thumb_down', 'Heart_single', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'Thumb_down', 'Nine', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Six', 'Rock', 'Rock', 'Rock', 'Rock', 'Rock', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One', 'One']

def add_bgm(bgm_label):
 
    count = len(bgm_label)
    print(count)
    
    #标记标签变化位置
    label_flag = [0]
    label = bgm_label[0]
    for i in range(count):
        if bgm_label[i]!=label:
            label_flag.append(i)
            label = bgm_label[i]
    label_flag.append(len(bgm_label)-1)
    #print(label_flag)
    
    
    label_flag_number = len(label_flag)
    
    for i in range(label_flag_number-1):
        #相应帧数对应标签
        flag = label_flag[i]
        label = bgm_label[flag]
        #print(label)
        #标签对应的音频序号
        number = bgm_dict[label]
        #print(number)
        
        start = float(label_flag[i]*0.033)
        end = float(label_flag[i+1]*0.033)
        
        #video = VideoFileClip('video/saveVideo.mp4')
        video = VideoFileClip('video/saveVideo.mp4').subclip(start,end)
        #视频长度
        v_duration = video.duration
        #print(v_duration)
        
        bgm_path = "bgm/%d.wav"%number
        #print(bgm_path)
        # 读取音频
        audio = AudioFileClip(bgm_path)
        
        # 设置视频的音频
        video = video.set_audio(audio)
        # 保存新的视频文件
        video.write_videofile('video/bgm_video/bws_audio%d.mp4'%i)
    

def video_merge():
    fileList = os.listdir('video/bgm_video/')
     
    count = 0
    for filename in fileList:
        count += 1
    
    #L存储拼接视频路径
    L = []
    for i in range(count):
        video = VideoFileClip('video/bgm_video/'+'bws_audio%d.mp4'%i)
        L.append(video)
    

    final_clip = concatenate_videoclips(L)
    final_clip.to_videofile('video/bgm_add_video.mp4')
    #final_clip.to_videofile('video/bgm_add_video.mp4', fps=30, remove_temp=False)

        
    
    
def add_bgm2(bgm_label):
  
    count = len(bgm_label)
    print(count)
    
    #标记标签变化位置
    label_flag = [0]
    label = bgm_label[0]
    for i in range(count):
        if bgm_label[i]!=label:
            label_flag.append(i)
            label = bgm_label[i]
    label_flag.append(len(bgm_label)-1)
    #print(label_flag)
    
    
    label_flag_number = len(label_flag)
    
    
    
    music = AudioSegment.from_wav('bgm/1.wav')
    clip = music[:0.0001*1000]
    
    for i in range(label_flag_number-1):
        #相应帧数对应标签
        flag = label_flag[i]
        label = bgm_label[flag]
        #print(label)
        #标签对应的音频序号
        number = bgm_dict[label]
        number = int(number)
        #print(number)
        
        start = float(label_flag[i]*0.033)
        end = float(label_flag[i+1]*0.034)
        
        bgm_len = float(end-start)
        
        bgm_path = "bgm/%d"%number + ".wav"
        
        music = AudioSegment.from_wav(bgm_path)
        
        clip = clip + music[:bgm_len*1000]
      
        
        
    clip.export('bgm/clip.wav', format='wav')
        
  
def video_merge2(outpath):
    
     bgm_path = "bgm/clip.wav"
     #print(bgm_path)
     # 读取音频
     audio = AudioFileClip(bgm_path)
       
     video = VideoFileClip('video/saveVideo.mp4')
     
     # 设置视频的音频
     video = video.set_audio(audio)
     
     video.write_videofile(outpath)
     
        
def add_bgm3(bgm_label):
  
    count = len(bgm_label)
    #print(count)
    
    #标记标签变化位置
    label_flag = [0]
    label = bgm_label[0]
    for i in range(count):
        if bgm_label[i]!=label:
            label_flag.append(i)
            label = bgm_label[i]
    label_flag.append(len(bgm_label)-1)
    #print(label_flag)
    
    
    label_flag_number = len(label_flag)
     
    
    music = AudioSegment.from_wav('bgm/1.wav')
    clip = music[:0.0001*1000]
    
    
    for i in range(label_flag_number-1):
        #相应帧数对应标签
        flag = label_flag[i]
        label = bgm_label[flag]

        #标签对应的音频序号
        number = bgm_dict[label]
        number = int(number)
        #print(number)
   
        #去除手势变换识别错误标签
        if_or_not = int(label_flag[i+1]-label_flag[i])

        
        if if_or_not < 12:
            start = float(label_flag[i]*0.033)
            end = float(label_flag[i+1]*0.033)
            
            bgm_len = float(end-start)
            #print(bgm_len)
            
            bgm_path = 'bgm/0.wav'
            
            music = AudioSegment.from_wav(bgm_path)
        
            clip = clip + music[:bgm_len*1000]
            
        elif if_or_not > 30:
            start = float(label_flag[i]*0.033)
            end = float(label_flag[i+1]*0.033)
            
            bgm_len = float(end-start)
            #print(bgm_len)
            
            bgm_path = "bgm/%d"%number + ".wav"
            
            music = AudioSegment.from_wav(bgm_path)
        
            clip = clip + music[:30*0.033*1000]
            
            bgm_path = 'bgm/0.wav'
            
            music = AudioSegment.from_wav(bgm_path)
        
            clip = clip + music[:(if_or_not-30)*0.033*1000]
            
        else:              
            start = float(label_flag[i]*0.033)
            end = float(label_flag[i+1]*0.033)
            
            bgm_len = float(end-start)
            #print(bgm_len)
            
            bgm_path = "bgm/%d"%number + ".wav"
            
            music = AudioSegment.from_wav(bgm_path)
            
            clip = clip + music[:bgm_len*1000]
      
    clip.export('bgm/clip.wav', format='wav')
 
    
def add_bgm34(bgm_label):
  
    count = len(bgm_label)
    print(count)
    
    #标记标签变化位置
    label_flag = [0]
    label = bgm_label[0]
    for i in range(count):
        if bgm_label[i]!=label:
            label_flag.append(i)
            label = bgm_label[i]
    label_flag.append(len(bgm_label)-1)
    #print(label_flag)
    
    
    label_flag_number = len(label_flag)
     
    
    music = AudioSegment.from_wav('bgm/1.wav')
    clip = music[:0.0001*1000]
    
    totle_len = 0
    
    for i in range(label_flag_number-1):
        #相应帧数对应标签
        flag = label_flag[i]
        label = bgm_label[flag]
        #print(label)
        #标签对应的音频序号
        number = bgm_dict[label]
        number = int(number)
        #print(number)
   
        #去除手势变换识别错误标签
        if_or_not = int(label_flag[i+1]-label_flag[i])
        #print(if_or_not)
        
        if if_or_not < 8:
            start = float(label_flag[i]*0.033)
            end = float(label_flag[i+1]*0.033)
            
            bgm_len = float(end-start)
            #print(bgm_len)
            totle_len += bgm_len
            #print(totle_len)
            
            bgm_path = 'bgm/0.wav'
            
            music = AudioSegment.from_wav(bgm_path)
        
            clip = clip + music[:bgm_len*1000]
            
        elif if_or_not > 30:
            start = float(label_flag[i]*0.033)
            end = float(label_flag[i+1]*0.033)
            
            bgm_len = float(end-start)
            #print(bgm_len)
            totle_len += bgm_len
            #print(totle_len)
            
            bgm_path = "bgm/%d"%number + ".wav"
            
            music = AudioSegment.from_wav(bgm_path)
        
            clip = clip + music[:30*0.033*1000]
            
            bgm_path = 'bgm/0.wav'
            
            music = AudioSegment.from_wav(bgm_path)
        
            clip = clip + music[:(if_or_not-30)*0.033*1000]
            
        else:              
            start = float(label_flag[i]*0.033)
            end = float(label_flag[i+1]*0.033)
            
            bgm_len = float(end-start)
            #print(bgm_len)
            totle_len += bgm_len
            #print(totle_len)
            
            bgm_path = "bgm/%d"%number + ".wav"
            
            music = AudioSegment.from_wav(bgm_path)
            
            clip = clip + music[:bgm_len*1000]
      
    clip.export('bgm/clip.wav', format='wav')
    #print(totle_len)   
        

#add_bgm3(label)


